package com.lhg.udp;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class client {
    public static void main(String[] args) throws IOException {
        DatagramSocket socket = new DatagramSocket(8080);

        byte[] buffer = new byte[100];
        DatagramPacket packet = new DatagramPacket(buffer,0,buffer.length);

        // 接收
        socket.receive(packet);
        // packet.getData() 用来获取数据报的数据
        // packet.getLength() 用来获取读取的数据报的长度
        String str = new String(packet.getData(), 0, packet.getLength());
        System.out.println(str);

        socket.close();
    }
}
